package com.heba.greenmulu;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import com.heba.config.CommonConfig;
import com.heba.helper.MemberShipHelper;
import com.heba.utils.ToastShow;

/**
 * 舉報頁面
 * Created by jason on 2020/3/30.
 */
public class ItemReportActivity extends BaseActivity {

    private EditText et_report;
    private Button btn_confirm;

    private int type;   //判斷是舉報日記還是舉報用戶
    private String reportID;  //舉報ID

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_diary_report);
        initTopbar();
        findViewById();
        initView();
    }

    @Override
    protected void findViewById() {
        et_report = findViewById(R.id.et_report);
        btn_confirm = findViewById(R.id.btn_confirm);
    }

    @Override
    protected void initView() {
        Bundle bundle = getIntent().getExtras();
        if (null != bundle) {
            type = bundle.getInt(CommonConfig.TYPE, 0);
            reportID = bundle.getString(CommonConfig.REPORT_ID, "");
        }

        switch (type) {
            case 1:
                //舉報用戶
                txt_title.setText(this.getResources().getString(R.string.mine_report));
                break;
            case 2:
                //舉報日記
                txt_title.setText(this.getResources().getString(R.string.diary_report));
                break;
            default:
                break;
        }

        /**
         * 提交舉報信息
         */
        btn_confirm.setOnClickListener(v -> {
            if (et_report.getText().toString().trim().isEmpty()) {
                ToastShow.displayToast(ItemReportActivity.this, getResources().getString(R.string.diary_report_input_tips));
                return;
            }
            loading.Start();
            new MemberShipHelper(new MemberShipHelper.MembershipListener() {
                @Override
                public void Success() {
                    loading.End();
                    finishActivity();
                    ToastShow.displayToast(ItemReportActivity.this, getResources().getString(R.string.diary_report_success));
                }

                @Override
                public void Fail(String error) {
                    loading.End();
                    ToastShow.displayToast(ItemReportActivity.this, getResources().getString(R.string.diary_report_failure));
                }
            }).reportContent(ItemReportActivity.this, type, reportID, et_report.getText().toString());
        });
    }
}
